import { controller, all, post, get } from "../decorator/router";
import { wiki } from "../api";
const { getHouses, getHouse, getCharacters, getCharacter } = wiki;
@controller("/wiki")
class Wechat {
  constructor() {}

  @get("/houses")
  async getHouses(ctx, next) {
    const data = await getHouses();
    ctx.body = {
      success: true,
      data
    };
  }

  @get("/houses/:name")
  async getHouse(ctx, next) {
    const { params: { name } } = ctx;
    if (!name) {
      return (ctx.body = {
        success: false,
        err: "name is required"
      });
    }
    const data = await getHouse(name);

    ctx.body = {
      success: true,
      data
    };
  }

  @get("/characters")
  async getCharacters(ctx, next) {
    const {p,c} = ctx.query;
    const data = await getCharacters(Number(p),Number(c));
    ctx.body = {
      success: true,
      data:data
    };
  }

  @get("/characters/:_id")
  async getCharacter(ctx, next) {
    const { params: { _id } } = ctx;
    if (!_id) {
      return (ctx.body = {
        success: false,
        err: "_id is required"
      });
    }
    const data = await getCharacter(_id);

    ctx.body = {
      success: true,
      data
    };
  }
}
